<?php
/**
 *
 * @category   JND
 * @package    Jnd_View
 * @subpackage Helper
 * @copyright  Copyright (c) 2005-2009 DDB
 * @version    1.0.0
 */
/**
 * Abstract class for extension
 */
require_once 'Zend/View/Helper/FormElement.php';
/**
 * Helper to generate a "Select" element
 *
 * @category   JND
 * @package    Jnd_View
 * @subpackage Helper
 */
class Jnd_View_Helper_FormSelectNameNice extends Zend_View_Helper_FormSelect
{

    /**
     * Generates a 'hidden' element.
     *
     * @access public
     *
     * @param string|array $name If a string, the element name.  If an
     * array, all other parameters are ignored, and the array elements
     * are extracted in place of added parameters.
     * @param mixed $value The element value.
     * @param array $attribs Attributes for the element tag.
     * @return string The element XHTML. div tag + input hidden tag
     */
    public function formSelectNameNice($name, $value = null, $attribs = null, $options = null, $listsep = "<br />\n")
    {
        $info = $this->_getInfo($name, $value, $attribs, $options, $listsep);
        $view = $this->view;
        $choix = new Jnd_View_Helper_FormAutocomplete();
        $html = $choix->formAutocomplete("tmp" . $name, $value, $attribs);
        unset($attribs['size']);
        $attribs['multiple'] = true;
        $attribs['style'] = "display: none;";
        $select = new Zend_View_Helper_FormSelect();
        $select->view = $view;
        $selectHtml = $select->formSelect($name, $value, $attribs, $options);
        $class = (is_array($value) && count($value) > 0 ? "visible" : "cache");
        $selectDiv = "<div id='div" . str_replace(
            array("[", "]"),
            array("-", ""), $name) . "' class='select-autocomplete " . $class . "'>";
        $idDivDest = 'div' . str_replace(
            array("[", "]"),
            array("-", ""), $name);
        $idSelect = str_replace(array("[", "]"),
            array("-", ""), $name);
        if (is_array($value)) {
            foreach ($value as $value => $display) {
                $idSpan = str_replace(
                    array("=", " ", "/",
                        ","),
                    array(""), $value);
                $displayModif = str_replace(
                    array("CN=", ",OU=",
                        "DC=net,DC=lan",
                        ","),
                    array("", "/", "",
                        ""),
                    $display);
                $image = '<img src="/images/supprimerListe.png" alt="Supprimer" border="0" onclick="supprimerNaSelect(\'' . $idSpan . "', '" . $display . "', '" . $displayModif . "', '" . $idDivDest . "', '" . $idSelect . '\')" />';
                $selectDiv .= '<div id="' . $idSpan . '">' . $displayModif . $image . '</div>';
            }
        }
        $selectDiv .= "</div>";
        $html .= "<br />$selectDiv" . $selectHtml;
        return $html;
    }
}
